package com.zbp.web;

import com.zbp.config.exception.Result;
import com.zbp.model.User;
import com.zbp.model.vo.UserVO;
import com.zbp.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户接口层
 */
@Slf4j
@RestController
@RequestMapping(value = "/user")
@Api(tags = "用户测试")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping(value = "/{user}")
    @ApiOperation(value = "根据名称获取用户信息")
    public Result<UserVO> get(@PathVariable String user) {
        return Result.success(userService.get(user));
    }

    @PostMapping(value = "/create")
    @ApiOperation(value = "创建用户")
    public Result<User> create(@RequestBody User user) {
        return Result.success(userService.create(user));
    }

    @PutMapping(value = "/update")
    @ApiOperation(value = "更新用户")
    public Result<User> update(@RequestBody User user) {
        return Result.success(userService.update(user));
    }


    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "删除用户")
    public Result<Boolean> delete(@PathVariable Long id) {
        userService.delete(id);
        return Result.success(true);
    }

}
